/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ADT;
import static ADT.Values.*;
/**
 *
 * @author Martin
 */
public class SpeedInMs extends Scalar implements Speed {
    private final double msec;
    
    @Override public boolean isValid(){return true;}
    @Override public boolean isZero(){return msec == 0;}
    
    private SpeedInMs(double  msec){
        this.msec =  msec;
    } 
    
    @Override public Speed inverse(){return new SpeedInMs(this.msec * -1);}
    
    @Override public double  getMS(){return msec;}
    
    @Override public double getKmH(){return msec * MSEC_TO_KMH;}
    
    @Override public Speed add(Speed speed){return valueOf(this.getMS() + speed.getMS());}
   
    @Override public Speed sub(Speed speed){return valueOf(this.getMS() - speed.getMS());}
    
    @Override public Speed div(double factor){return valueOf(this.msec / factor);}
    
    @Override public  Speed mul(double factor){return valueOf(this.msec * factor);}
    
    @Override public Length mul(TimeDiff time){return lengthInM(msec * time.s());}
    
    @Override public double div(Speed speed){return this.msec / speed.getMS();}
    
    @Override public TimeDiff div(Acc acc){return timeDiffInS(msec / acc.mss());}
   
    @Override public Force dragForce(Speed maxSpeed, Power maxPower){return forceInN(maxSpeed.getMS()* maxSpeed.getMS() * maxPower.getW());}
    public String toString(Speed speed){
        return String.format("%.2d M/S");
    }
    
    @Override
    public int compareTo(Speed speed){
        return Double.compare(this.msec, speed.getMS());
    }
    
    @Override
    public boolean equals(Object o){
        if(this == o) return true;
        if(!(o instanceof SpeedInMs)) return false;
        return this.compareTo((SpeedInMs)o) == 0;
    }
    
    
    public static Speed valueOf(double msec){
        return new SpeedInMs(msec);
    }
    
    @Override
    public int hashCode(){
        return hashDouble(msec);
    }
}
